package com.maimao.utils.excel.convert;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.checkerframework.checker.units.qual.C;

/**
 * Excel导出 订单类型转换器
 *
 * @author MaoLin Wang
 * @date 2021/6/7 上午11:37
 */
public class OrderTypeConvert implements Converter<Integer> {
    private static final Integer ONE = 1;
    private static final Integer TWO = 2;

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if ("普通订单".equals(cellData.getStringValue())) {
            return ONE;
        } else if ("秒杀订单".equals(cellData.getStringValue())) {
            return TWO;
        }
        return null;
    }

    @Override
    public CellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        CellData<String> cellData = new CellData<>();
        if (value == null) {
            return new CellData<>("---");
        } else if (value.equals(ONE)) {
            return new CellData<>("普通订单");
        } else if (value.equals(TWO)) {
            return new CellData<>("秒杀订单");
        } else {
            return new CellData<>("---");
        }
    }
}
